<template>
  <div class="goods-comment-image">
    <div class="list">
      <a
        href="javascript:;"
        :class="{active: curIndex === index}"
        @click="curIndex = index"
        v-for="(item,index) in imageList"
        :key="item"
      >
        <img :src="item" alt="">
      </a>
    </div>
    <!-- curIndex默认为null，预览未开启，点击图片时不是null -->
    <div class="preview" v-if="curIndex !== null">
        <img :src="imageList[curIndex]" alt="">
         <i @click="curIndex = null" class="iconfont icon-close-new"></i>
    </div>
  </div>
</template>
<script>
import { ref } from 'vue'
export default {
  name: 'GoodsCommentImage',
  props: {
    imageList: {
      type: Array
    }
  },
  setup () {
    // 当前显示图片url
    const curIndex = ref(null)
    return { curIndex }
  }
}
</script>
<style scoped lang="less">
.goods-comment-image {
  .list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    a {
      width: 120px;
      height: 120px;
      border:1px solid #e4e4e4;
      margin-right: 20px;
      margin-bottom: 10px;
      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
      &.active {
        border-color: @xtxColor;
      }
    }
  }
  .preview {
      position: relative;
      img {
          width: 100%;
      }
      i {
          position: absolute;
          top: 0;
          right: 0;
          width: 30px;
          height: 30px;
          background-color: #ccc;
          text-align: center;
          line-height: 30px;
      }
  }
}
</style>
